package JavaTest.sectionTest;

public class Test01 {
    public static void main(String[] args) {
        //计算两个double类型的数是否相等
//        double num1 = 2.7;
//        double num2 = 8.1/3;
//        System.out.println(isEqual(num1,num2));

        //打印金字塔
//        emptyPyramid(6);
        printYangHuiTriangle(5);
    }
    public static boolean isEqual(double a,double b){
        return Math.abs(a - b) < 0.00001;
    }

//    public static String twoToTen(){
//        String ten = "";
//        return ten;
//    }

    public static void emptyPyramid(int level){
        for (int i = 0; i < level; i++) {
            for (int j = 0; j < ((level-i-1)); j++) {
                System.out.print(" ");
            }
            if (i == level-1){
                for (int j = 1; j <= 2*i+1; j++) {
                    System.out.print("*");
                }
            }else {
                for (int j = 1; j <= 2*i+1; j++) {
                    if (j == 1 || j ==2*i+1){
                        System.out.print("*");
                    }else System.out.print(" ");
                }
            }

            System.out.println();
        }
    }

    public static void printYangHuiTriangle(int level){
        int[][] YangHuiTriangle = new int[level][level];
        for (int i = 0; i < level; i++) {
            for (int j = 0; j <= i ; j++) {
                if (j == 0){
                    YangHuiTriangle[i][j] = 1;
                    System.out.print(1);
                }else if (j == i){
                    YangHuiTriangle[i][j] = 1;
                    System.out.print(1);
                }else {
                    YangHuiTriangle[i][j] = YangHuiTriangle[i-1][j] + YangHuiTriangle[i-1][j-1];
                    System.out.print(YangHuiTriangle[i][j]);
                }

            }
            System.out.println();
        }
    }
}
